<template>
  <section class="main">
    <input
      id="toggle-all"
      class="toggle-all"
      type="checkbox"
      v-model="suoyou"
    />
    <label for="toggle-all">全部标记为已完成</label>
    <ul class="todo-list">
      <!-- These are here just to show the structure of the list items -->
      <!-- List items should get the class `editing` when editing and `completed` when marked as completed -->
      <li
        :class="{ completed: item.isDone }"
        v-for="item in list"
        :key="item.id"
      >
        <div class="view">
          <input
            class="toggle"
            type="checkbox"
            :checked="item.isDone"
            @change="$emit('state', item.id)"
          />
          <label>{{ item.name }}</label>
          <button class="destroy" @click="$emit('del', item.id)"></button>
        </div>
        <input class="edit" value="Create a TodoMVC template" />
      </li>
    </ul>
  </section>
</template>

<script>
export default {
  // props: ['list']
  props: {
    list: Array, // 表示父组件传递过来的必须是数组
  },
  computed: {
    suoyou: {
      get() {
        return this.list.every((item) => item.isDone)
      },
      set(val) {
        // console.log(val) // true | false
        // 当修改了大复选框的值，我们要更新全部的小复选框
        this.$emit('changeAll', val)
      },
    },
  },
}
</script>

<style>
</style>